package servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class HiServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("HiServlet 被调用...");

        //servlet中可以使用哪些对象
        PrintWriter writer = resp.getWriter();
        writer.println("haha");
        String age = req.getParameter("age");
        resp.setContentType("text/html");

        HttpSession session = req.getSession();
        session.setAttribute("job", "java工程师");

        ServletContext servletContext = req.getServletContext();
        servletContext.setAttribute("count", 666);

        ServletConfig servletConfig = super.getServletConfig();
    }
}
